package com.jctrip.hotel.management.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jctrip.hotel.management.model.param.*;
import com.jctrip.hotel.management.model.result.*;
import com.jctrip.hotel.management.service.SystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@Api(tags = "management-system")
@RestController
@RequestMapping("/sys")
public class SystemController {

    @Autowired
    private SystemService systemService;

    @PostMapping("/user/login")
    @ApiOperation(value = "login", notes = "用户登录")
    @ApiOperationSupport(order = 1)
    public Result<LoginResult> userLogin(@RequestBody LoginParam param, HttpServletRequest request){
        return Result.ok(systemService.userLogin(param, request));
    }

    @GetMapping("/user")
    @ApiOperation(value = "user", notes = "获取权限列表")
    @ApiOperationSupport(order = 2)
    public Result<GetUserResult> user(HttpServletRequest request){
        return Result.ok(systemService.user(request));
    }

    @GetMapping("/user/list")
    @ApiOperation(value = "user/list", notes = "用户列表")
    @ApiOperationSupport(order = 3)
    public Result<GetUserListResult> userList(@RequestParam(value = "pageNo", required = false, defaultValue = "1")Long pageNo,
                           @RequestParam(value = "pageSize", required = false, defaultValue = "10")Long pageSize){
        return Result.ok(systemService.userList(pageNo, pageSize));
    }

    @PostMapping("/user/editInfo")
    @ApiOperation(value = "user/editInfo", notes = "用户基本信息编辑")
    @ApiOperationSupport(order = 4)
    public Result<String> userEditInfo(@RequestBody UpdateUserInfoParam param){
        return Result.ok(systemService.userEditInfo(param));
    }

    @PostMapping("/user/editPermissions")
    @ApiOperation(value = "user/editPermissions", notes = "用户权限编辑")
    @ApiOperationSupport(order = 5)
    public Result<String> userEditPermissions(@RequestBody UpdateUserPerminssionsParam param){
        return Result.ok(systemService.userEditPermissions(param));
    }

    @PostMapping("/user/add")
    @ApiOperation(value = "user/add", notes = "用户添加")
    @ApiOperationSupport(order = 5)
    public Result<String> userAdd(@RequestBody InsertUserInfoParam param){
        return Result.ok(systemService.userAdd(param));
    }

    @PostMapping("/user/delete")
    @ApiOperation(value = "user/delete", notes = "用户添加")
    @ApiOperationSupport(order = 6)
    public Result<String> userDelete(@RequestBody RemoveUserInfoParam param){
        return Result.ok(systemService.userDelete(param));
    }

    @GetMapping("/homepage")
    @ApiOperation(value = "homepage", notes = "主页接口")
    @ApiOperationSupport(order = 7)
    public Result<GetHomepageResult> homepage(HttpServletRequest request){
        return Result.ok(systemService.homepage(request));
    }

    @GetMapping("/permissions")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "permissions", notes = "路由菜单表接口")
    public Result<List<GetPermissionInfo>> permissions(){
        return Result.ok(systemService.permissions());
    }

}
